package com.yunyun400.vosk.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.yunyun400.vosk.entity.ReminderRecord;
import com.yunyun400.vosk.service.ReminderService;

/**
 * 提醒控制器
 * 提供API接口用于查看和管理检测到关键词的提醒记录
 */
@RestController
@RequestMapping("/api/reminders")
public class ReminderController {
    
    @Autowired
    private ReminderService reminderService;
    
    /**
     * 获取所有提醒记录
     */
    @GetMapping
    public ResponseEntity<List<ReminderRecord>> getAllReminders() {
        List<ReminderRecord> reminders = reminderService.getAllReminders();
        return new ResponseEntity<>(reminders, HttpStatus.OK);
    }
    
    /**
     * 获取未处理的提醒记录
     */
    @GetMapping("/unprocessed")
    public ResponseEntity<List<ReminderRecord>> getUnprocessedReminders() {
        List<ReminderRecord> unprocessedReminders = reminderService.getUnprocessedReminders();
        return new ResponseEntity<>(unprocessedReminders, HttpStatus.OK);
    }
    
    /**
     * 根据批次ID获取提醒记录
     */
    @GetMapping("/batch/{batchId}")
    public ResponseEntity<List<ReminderRecord>> getRemindersByBatchId(@PathVariable String batchId) {
        List<ReminderRecord> batchReminders = reminderService.getRemindersByBatchId(batchId);
        return new ResponseEntity<>(batchReminders, HttpStatus.OK);
    }
    
    /**
     * 标记提醒记录为已处理
     */
    @PostMapping("/{reminderId}/process")
    public ResponseEntity<String> markReminderAsProcessed(@PathVariable String reminderId) {
        boolean success = reminderService.markAsProcessed(reminderId);
        if (success) {
            return new ResponseEntity<>("提醒记录已标记为已处理", HttpStatus.OK);
        } else {
            return new ResponseEntity<>("未找到指定的提醒记录", HttpStatus.NOT_FOUND);
        }
    }
}